# https://www.cnblogs.com/alex-13/p/12016554.html
# https://zhuanlan.zhihu.com/p/127837363
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait
from selenium import webdriver
import time

# 声明浏览器
browser = webdriver.Chrome()

# 找到html文件并打开
Path_name = 'D:/gitworkspace/python100/Day51/selenium.html'
browser.get(Path_name)
browser.maximize_window()

# 查找元素并操作
User_name = browser.find_element_by_css_selector('div#signup [name="username"]').send_keys('rabbit')
time.sleep(2)
Pass_word = browser.find_element_by_css_selector('div#signup [name="password"]').send_keys('love')
time.sleep(2)
City_select = Select(browser.find_element_by_name('city'))
City_select.select_by_value('sz')

Submit_button = browser.find_element_by_css_selector('div#signup form').submit()
time.sleep(3)

# 显示等待
success = WebDriverWait(browser, 10, 1).until(
    lambda x: x.find_element_by_css_selector("div#signup p").text == "注册成功")

# 关闭浏览器
browser.quit()